package com.aggron.controller;


import com.aggron.bean.PageQuery;
import com.aggron.common.JsonData;
import com.aggron.constants.ControllerConstants;
import com.aggron.params.UserParams;
import com.aggron.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuhuan
 * @since 2018-06-02
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private ISysUserService iSysUserService;

    @GetMapping("/getUsers")
    public JsonData getUsers(PageQuery pageQuery,UserParams userParams){

        return JsonData.success(iSysUserService.pageUser(pageQuery,userParams));
    }

    @PostMapping("/save")

    public JsonData save(@RequestBody  UserParams userParams){
        iSysUserService.save(userParams);
        return JsonData.success(ControllerConstants.ADD_SUCCESS_MESSAGE);
    }

    @PostMapping("/update")
    public JsonData update(@RequestBody UserParams userParams){
        iSysUserService.update(userParams);
        return JsonData.success(ControllerConstants.UPDATE_SUCCESS_MESSAGE);
    }

    @PostMapping("/delete")
    public JsonData delete(@RequestBody UserParams userParams){
        iSysUserService.deleteLogic(userParams.getId());
        return JsonData.success(ControllerConstants.DELETE_SUCCESS_MESSAGE);
    }


}

